// 编写 ESModule 语句?   不可以
const path = require("path");
const htmlWebpackPlugin = require('html-webpack-plugin')
//配置
module.exports = {
  //入口
  entry: "./src/index.ts",
  //出口
  output: {
    path: path.resolve(__dirname, "./build"),
    filename: "js/bundle-[hash:8].js",
  },
  //loader
  module: {
    rules: [
      // css 处理
      {
        test: /\.css$/,
        use: ["style-loader", "css-loader"],
      },
      // ts 文件处理
      {
        test: /\.tsx?$/,
        use: "ts-loader",
      },
    ],
  },
  //解决
  resolve: {
    //扩展名   import test from './test'
    extensions: [".ts", ".tsx", ".js"],
  },
  //plugins
  plugins: [
    new htmlWebpackPlugin({
      template: './public/index.html'
    })
  ],

  //模式
  mode: 'development',

  //开发服务
  devServer: {
    port: 12563, //监听端口 3000
    open: true, //自动打开浏览器
    hot: true
  }
};
